<!DOCTYPE html>

<html lang="
zh-CN"
    >

        <head>
            
                <title>
                    
                        JAVA-常用类 -
                            
                                shanX&#39;s Blog
                </title>
                <meta charset="UTF-8">
                <meta name="description" content="">
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
                
                    

                        <link rel="shortcut icon" href="/image/author.png" type="image/png" />
                        <meta name="description" content="常用类">
<meta property="og:type" content="article">
<meta property="og:title" content="JAVA-常用类">
<meta property="og:url" content="https://rhymexmove.github.io/2021/04/06/e3cec34b39ef/index.html">
<meta property="og:site_name" content="shanX&#39;s Blog">
<meta property="og:description" content="常用类">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-06T14:29:11.000Z">
<meta property="article:modified_time" content="2022-04-07T17:25:27.693Z">
<meta property="article:author" content="shanX">
<meta property="article:tag" content="java基础">
<meta name="twitter:card" content="summary">
                            <link rel="stylesheet" href="https://cdn.jsdelivr.net/combine/npm/highlight.js@9.15.8/styles/atom-one-dark.css,gh/theme-nexmoe/hexo-theme-nexmoe@latest/source/lib/mdui_043tiny/css/mdui.css,gh/theme-nexmoe/hexo-theme-nexmoe@latest/source/lib/iconfont/iconfont.css,gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css?v=233"
                                crossorigin>
                            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.8.1/dist/css/justifiedGallery.min.css">
                            <!--适用于 Retina 屏的 iPad-->
                            <link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png">
                            <!--适用于 Retina 屏的 iPhone-->
                            <link rel="apple-touch-icon-precomposed" sizes="120x120" href="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png">
                            <!--适用于非 Retina 屏的 iPad-->
                            <link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png">
                            <!--适用于非 Retina 屏的 iPhone-->
                            <link rel="apple-touch-icon-precomposed" href="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png">
                            
                                <link rel="stylesheet" href="//at.alicdn.com/t/font_2490857_fmjyoao96km.css">
                                
                                    <link rel="stylesheet" href="/css/style.css?v=1649858550960">
        <meta name="generator" content="Hexo 5.4.0"></head>

        <body class="mdui-drawer-body-left">
            
                <div id="nexmoe-background">
                    <div class="nexmoe-bg" style="background-image: url(https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/cover/5887c2f1-b191-4890-aab5-2ce62d9955df.jpg)"></div>
                    <div class="mdui-appbar mdui-shadow-0">
                        <div class="mdui-toolbar">
                            <a mdui-drawer="{target: '#drawer', swipe: true}" title="menu" class="mdui-btn mdui-btn-icon mdui-ripple"><i class="mdui-icon nexmoefont icon-menu"></i></a>
                            <div class="mdui-toolbar-spacer"></div>
                            <!--<a href="javascript:;" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">search</i></a>-->
                            <a href="/" title="shanX" class="mdui-btn mdui-btn-icon"><img src="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png" alt="shanX"></a>
                        </div>
                    </div>
                </div>
                <div id="nexmoe-header">
                    <div class="nexmoe-drawer mdui-drawer" id="drawer">
    <div class="nexmoe-avatar mdui-ripple">
        <a href="/" title="shanX">
            <img src="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/author.png" alt="shanX" alt="shanX">
        </a>
    </div>
    <div class="nexmoe-count nexmoe-widget-wrap">
        <div><span>文章</span>30</div>
        <div><span>标签</span>16</div>
        <div><span>分类</span>8</div>
    </div>
    <div class="nexmoe-list mdui-list nexmoe-widget-wrap" mdui-collapse="{accordion: true}">
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple" href="/" title="回到首页">
            <i class="mdui-list-item-icon nexmoefont icon-home"></i>
            <div class="mdui-list-item-content">
                回到首页
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple" href="/archives.html" title="文章归档">
            <i class="mdui-list-item-icon nexmoefont icon-container"></i>
            <div class="mdui-list-item-content">
                文章归档
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple" href="/cesium-test/index.html" title="Cesium">
            <i class="mdui-list-item-icon nexmoefont icon-Cesium-copy"></i>
            <div class="mdui-list-item-content">
                Cesium
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple" href="/cesium-covid/index.html" title="全球疫情">
            <i class="mdui-list-item-icon nexmoefont icon-areachart"></i>
            <div class="mdui-list-item-content">
                全球疫情
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple" href="/about.html" title="关于博客">
            <i class="mdui-list-item-icon nexmoefont icon-info-circle"></i>
            <div class="mdui-list-item-content">
                关于博客
            </div>
        </a>
        
    </div>
    <aside id="nexmoe-sidebar">
  
  <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-search">
        <form id="search_form" action_e="https://cn.bing.com/search?q=rhymexmove.github.io" onsubmit="return search();">
            <label><input id="search_value" name="q" type="search" placeholder="搜索"></label>
        </form>
    </div>
</div>
  
  <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-social">
        <a class="mdui-ripple" href="https://space.bilibili.com/20666214" target="_blank" mdui-tooltip="{content: '哔哩哔哩'}" style="color: rgb(231, 106, 141);background-color: rgba(231, 106, 141, .15);">
            <i class="nexmoefont icon-bilibili"></i>
        </a><a class="mdui-ripple" href="https://github.com/RhymeXmove/" target="_blank" mdui-tooltip="{content: 'GitHub'}" style="color: rgb(231, 106, 141);background-color: rgba(231, 106, 141, .15);">
            <i class="nexmoefont icon-github"></i>
        </a><a class="mdui-ripple" href="https://gitee.com/shanxin123/" target="_blank" mdui-tooltip="{content: 'Gitee'}" style="color: rgb(220,20,60);background-color: rgba(220,20,60, .15);">
            <i class="nexmoefont icon-gitee"></i>
        </a>
    </div>
</div>
  
  
    <div class="nexmoe-widget-wrap">
        <h3 class="nexmoe-widget-title">
            文章分类
        </h3>
        <div class="nexmoe-widget">

            <ul class="category-list">

                


                    

                        

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/mysql/">
                                    -mysql
                                </a>
                                <span class="category-list-count">1</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/Cesium/">
                                    Cesium
                                </a>
                                <span class="category-list-count">3</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/DB/">
                                    DB
                                </a>
                                <span class="category-list-count">2</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/Leetcode/">
                                    Leetcode
                                </a>
                                <span class="category-list-count">4</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/Vue/">
                                    Vue
                                </a>
                                <span class="category-list-count">2</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/blog搭建/">
                                    blog搭建
                                </a>
                                <span class="category-list-count">1</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/java/">
                                    java
                                </a>
                                <span class="category-list-count">12</span>
                            </li>

                            

                            <li class="category-list-item">
                                <a class="category-list-link" href="/categories/资源/">
                                    资源
                                </a>
                                <span class="category-list-count">1</span>
                            </li>

                            
            </ul>

        </div>
    </div>
    
  
  
  <div class="nexmoe-widget-wrap">
    <div id="randomtagcloud" class="nexmoe-widget tagcloud nexmoe-rainbow">
      <a href="/tags/DB/" style="font-size: 10px;">-DB</a> <a href="/tags/Cesium/" style="font-size: 12.5px;">Cesium</a> <a href="/tags/GIS/" style="font-size: 10px;">GIS</a> <a href="/tags/Leetcode/" style="font-size: 15px;">Leetcode</a> <a href="/tags/Vue/" style="font-size: 12.5px;">Vue</a> <a href="/tags/blog%E6%90%AD%E5%BB%BA/" style="font-size: 10px;">blog搭建</a> <a href="/tags/echart/" style="font-size: 10px;">echart</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/java%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">java基础</a> <a href="/tags/mysql/" style="font-size: 10px;">mysql</a> <a href="/tags/spring/" style="font-size: 10px;">spring</a> <a href="/tags/vue/" style="font-size: 10px;">vue</a> <a href="/tags/%E6%89%B9%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7/" style="font-size: 10px;">批处理工具</a> <a href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" style="font-size: 10px;">数据库</a> <a href="/tags/%E7%8B%82%E7%A5%9E%E8%AF%B4/" style="font-size: 17.5px;">狂神说</a> <a href="/tags/%E8%B5%84%E6%BA%90/" style="font-size: 10px;">资源</a>
    </div>
    
  </div>

  
  
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">文章归档</h3>
    <div class="nexmoe-widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/">2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/">2021</a><span class="archive-list-count">29</span></li></ul>
    </div>
  </div>



  
  
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">最新文章</h3>
    <div class="nexmoe-widget">
      <ul>
        
          <li>
            <a href="/2022/04/13/7533e8f3cb4c/">mysql查询数据库内全部表名；查询表内全部字段名</a>
          </li>
        
          <li>
            <a href="/2021/09/26/ee931b51117c/">什么是计算机图形学？</a>
          </li>
        
          <li>
            <a href="/2021/09/08/9adeea845004/">中国城市坐标(包含市辖区)</a>
          </li>
        
          <li>
            <a href="/2021/08/31/7ba201dda6cb/">Cesium billboard贴地形表</a>
          </li>
        
          <li>
            <a href="/2021/08/09/0d3ed7d31d83/">Vue中使用Vue-jsonp请求jsonp数据</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
    <div class="nexmoe-copyright">
        &copy; 2022 shanX
        Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
        & <a href="https://github.com/theme-nexmoe/hexo-theme-nexmoe" target="_blank">Nexmoe</a>
        
    </div>
</div><!-- .nexmoe-drawer -->
                </div>
                <div id="nexmoe-content">
                    <div class="nexmoe-primary">
                        <div class="nexmoe-post">

  <div class="nexmoe-post-right">
    
      <div class="nexmoe-fixed">
        <div class="nexmoe-valign">
            <div class="nexmoe-toc">
                
                
                  <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%B1%BB"><span class="toc-number">1.</span> <span class="toc-text">常用类</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.1.</span> <span class="toc-text">内部类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.1.1.</span> <span class="toc-text">成员内部类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.1.2.</span> <span class="toc-text">静态内部类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%80%E9%83%A8%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.1.3.</span> <span class="toc-text">局部内部类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.1.4.</span> <span class="toc-text">匿名内部类</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Object%E7%B1%BB"><span class="toc-number">1.2.</span> <span class="toc-text">Object类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#getClass%E7%B1%BB"><span class="toc-number">1.2.1.</span> <span class="toc-text">getClass类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#hashcode%E7%B1%BB"><span class="toc-number">1.2.2.</span> <span class="toc-text">hashcode类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toString%E7%B1%BB"><span class="toc-number">1.2.3.</span> <span class="toc-text">toString类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#equals-%E7%B1%BB"><span class="toc-number">1.2.4.</span> <span class="toc-text">equals()类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#finalize-%E6%96%B9%E6%B3%95"><span class="toc-number">1.2.5.</span> <span class="toc-text">finalize()方法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8C%85%E8%A3%85%E7%B1%BB"><span class="toc-number">1.3.</span> <span class="toc-text">包装类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2%E4%B8%8E%E8%A3%85%E7%AE%B1%E3%80%81%E6%8B%86%E7%AE%B1"><span class="toc-number">1.3.1.</span> <span class="toc-text">类型转换与装箱、拆箱</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B4%E6%95%B0%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="toc-number">1.4.</span> <span class="toc-text">整数缓冲区</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#String%E7%B1%BB"><span class="toc-number">1.5.</span> <span class="toc-text">String类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#String-%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.1.</span> <span class="toc-text">String 常用方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A1%88%E4%BE%8B%E6%BC%94%E7%A4%BA"><span class="toc-number">1.5.1.1.</span> <span class="toc-text">案例演示</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#StringBuffer-%E5%92%8C-StringBuilder"><span class="toc-number">1.5.2.</span> <span class="toc-text">StringBuffer 和 StringBuilder</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#BigDecimal%E7%B1%BB"><span class="toc-number">1.6.</span> <span class="toc-text">BigDecimal类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%97%B6%E9%97%B4-Date%E7%B1%BB"><span class="toc-number">1.7.</span> <span class="toc-text">时间-Date类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%97%B6%E9%97%B4-Calendar%E7%B1%BB"><span class="toc-number">1.8.</span> <span class="toc-text">时间-Calendar类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SimpleDateFormat%E7%B1%BB"><span class="toc-number">1.9.</span> <span class="toc-text">SimpleDateFormat类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#System%E7%B1%BB"><span class="toc-number">1.10.</span> <span class="toc-text">System类</span></a></li></ol></li></ol>
                
            </div>
        </div>
      </div>
    
  </div>

  <article>
    
        <div class="nexmoe-post-cover" style="padding-bottom: NaN%;"> 
            <img data-src="https://cdn.jsdelivr.net/gh/RhymeXmove/blogimg@latest/cover/JAVA.png" data-sizes="auto" alt="JAVA-常用类" class="lazyload">
            <h1>JAVA-常用类</h1>
        </div>
    
    
    <div class="nexmoe-post-meta nexmoe-rainbow-fill" style="margin:10px 0!important;">
    <a><i class="nexmoefont icon-calendar-fill"></i>2021年04月06日</a>
    <a><i class="nexmoefont icon-areachart"></i>4.6k 字</a>
    <a><i class="nexmoefont icon-time-circle-fill"></i>大概 23 分钟</a>
</div>

    <h1 id="常用类"><a href="#常用类" class="headerlink" title="常用类"></a>常用类</h1><span id="more"></span>

<h2 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h2><p>成员内部类、静态内部类、局部内部类、匿名内部类</p>
<p>概念：在一个类的内部再定义一个完整的类</p>
<p>特点：</p>
<ul>
<li>编译之后可生成独立的字节码文件</li>
<li>内部类可直接访问外部类私有成员，而不破坏封装</li>
<li>可为外部类提供必要的内部功能组件</li>
</ul>
<pre><code class="java">Outer$Inner.class` `Outer.class
</code></pre>
<pre><code class="java">// 身体
class Body&#123;
  // 头部
  class Header&#123;
    // 也会生成class文件
  &#125;
&#125;
</code></pre>
<h3 id="成员内部类"><a href="#成员内部类" class="headerlink" title="成员内部类"></a><strong>成员内部类</strong></h3><ul>
<li>在类的内部定义，与实例变量、实例方法同级别的类</li>
<li>外部类的一个实例部分，创建内部类对象时，必须依赖外部类对象</li>
<li>当外部类、内部类存在重名属性时，会优先访问内部类属性</li>
<li>成员内部类里不能定义<strong>静态成员</strong>、可以包含<strong>静态常量(final)</strong></li>
</ul>
<pre><code class="java">// 外部类
public class Outer&#123;
  //实例变量
  private String name = &quot;张三&quot;;
  private int age = 20;
  //内部类
  class Inner&#123;
    private String address = &quot;北京&quot;;
    private String phone = &quot;110&quot;;
    private String name = &quot;李四&quot;;
    
    //方法
    public void show()&#123;
      //打印外部类属性 此时有重名属性name
      sout(Outer.this.name); // 张三
      sout(age);
      //打印内部类中的属性
      sout(name); // 李四
      sout(address);
      sout(phone);
    &#125;
  &#125;
&#125;

// 测试类
public class Test&#123;
  psvm(String[] args)&#123;
    // 创建外部类对象
    Outer outer = new Outer();
    // 创建内部类对象
    Inner inner = outer.new Inner();
    
    //一步到位
    Inner inner = new Outer(.new Inner();
                            
    inner.show();
  &#125;
&#125;
</code></pre>
<h3 id="静态内部类"><a href="#静态内部类" class="headerlink" title="静态内部类"></a><strong>静态内部类</strong></h3><ul>
<li>不依赖外部类对象，可直接创建或通过类名访问，可声明静态成员</li>
</ul>
<pre><code class="java">// 外部类
public class Outer&#123;
  //实例变量
  private String name = &quot;xxx&quot;;
  private int age = 20;
  
  // 静态内部类，和外部类相同
  static class Inner&#123;
    private String address = &quot;上海&quot;;
    private String phone = &quot;111&quot;;
    // 静态成员
    private static int count = 1000;
    
    //方法
    public void show()&#123;
      // 调用外部类的属性
      // 1. 先创建外部类对象
      Outer outer = new Outer();
      // 2. 调用外部类对象的属性
      sout(outer.name);
      sout(outer.age);
      // 调用静态内部类的属性和方法
      sout(address);
      sout(phone);
      // 调用静态内部类的静态属性
      sout(Inner.count);
    &#125;
  &#125;
&#125;

// 测试类
public class Test&#123;
  psvm(String[] args)&#123;
    // 直接创建静态内部类对象
    Outer.Inner inner = new Outer.Inner();
                     
    inner.show();
  &#125;
&#125;
</code></pre>
<h3 id="局部内部类"><a href="#局部内部类" class="headerlink" title="局部内部类"></a><strong>局部内部类</strong></h3><ul>
<li>定义在外部类<strong>方法</strong>中，作用范围和创建对象范围仅限于当前方法</li>
<li>局部内部类访问外部类当前方法中的局部变量时，因无法保障变量的生命周期与自身相同，变量必须修饰为final</li>
<li>限制类的使用范围</li>
</ul>
<pre><code class="java">// 外部类
public class Outer&#123;
  //实例变量
  private String name = &quot;刘德华&quot;;
  private int age = 35;
  
  //方法
  public void show()&#123;
    // 定义局部变量
    String address = &quot;sz&quot;;
    
    // 局部内部类：注意不能加任何访问修饰符
    class Inner&#123;
      private String phone = &quot;11234&quot;;
      private String email = &quot;ldh@qq.com&quot;;
      
      public void show2()&#123;
        // 访问外部类的属性
        sout(name); // 相当于 Outer.this.name
        sout(age);
        // 访问内部类的属性
        sout(this.phone);
        sout(this.email);
        
        // 访问局部变量 jdk1.7要求必须常量final、jdk1.8自动添加final
        
      &#125;
    &#125;
    // 创建局部内部类对象
    Inner inner = new Inner();
    inner.show2();
  &#125;
&#125;

// 测试类
public class Test&#123;
  psvm(String[] args)&#123;
    // 创建外部类对象
    Outer outer = new Outer();
                     
    outer.show();
  &#125;
&#125;
</code></pre>
<h3 id="匿名内部类"><a href="#匿名内部类" class="headerlink" title="匿名内部类"></a><strong>匿名内部类</strong></h3><ul>
<li>没有类名的局部内部类（一切特征都与局部内部类相同）</li>
<li>必须继承一个父类或者实现一个接口</li>
<li>定义类、实现类、创建对象的语法合并，只能创建一个该类的对象</li>
<li>优点：减少代码量</li>
<li>缺点可读性较差</li>
</ul>
<pre><code class="Java">// 使用匿名内部类优化（相当于创建了一个局部内部类）
Usb usb = new Usb()&#123; // Usb为一个接口
  @Override
  public void service()&#123;
    sout(&quot;连接电脑成功，fan开始工作&quot;)
  &#125;
&#125;;
usb.service();
</code></pre>
<h2 id="Object类"><a href="#Object类" class="headerlink" title="Object类"></a>Object类</h2><ol>
<li>超类、基类，所有类的直接或间接父类，位于继承树的最顶层</li>
<li>任何类，如没有书写extends显示继承某个类，都默认直接继承Object类，否则为间接继承</li>
<li>Object类中所定义的方法，是所有对象都具备的方法</li>
<li>Object类型可以存储任何对象<ol>
<li>作为参数，可接受任何对象</li>
<li>作为返回值，可返回任何对象</li>
</ol>
</li>
</ol>
<h3 id="getClass类"><a href="#getClass类" class="headerlink" title="getClass类"></a>getClass类</h3><ol>
<li><p><code>public final Class&lt;?&gt; getClass()&#123;&#125;</code></p>
</li>
<li><p>返回引用中存储的实际对象类型</p>
</li>
<li><p>应用：通常用于判断两个引用中实际存储对象类型是否一致</p>
</li>
</ol>
<pre><code class="java">// 判断s1 和 s2是不是同一个类型
Class class1 = s1.getClass();
Class class2 = s2.getClass();
// getClass返回 class类型
</code></pre>
<h3 id="hashcode类"><a href="#hashcode类" class="headerlink" title="hashcode类"></a>hashcode类</h3><ol>
<li><code>public int hashCode()&#123;&#125;</code></li>
<li>返回该对象的哈希码值</li>
<li>哈希值根据对象的地址或字符串或数字使用hash算法计算出来的int类型的值</li>
<li>一般情况下相同对象返回相同哈希码</li>
</ol>
<pre><code class="java">s1.hashCode();
s2.hashCode();
// 自然不同  hashcode s1 != s2
Student s3 = s1;
s3.hashCode();
// s3的hashCode与s1相同,将s1赋给s3
</code></pre>
<h3 id="toString类"><a href="#toString类" class="headerlink" title="toString类"></a>toString类</h3><ol>
<li><code>public String toSring()&#123;&#125;</code></li>
<li>返回该对象的字符串表示（表现形式）</li>
<li>可以根据程序需求覆盖该方法，如：展示对象各个属性值</li>
</ol>
<pre><code class="java">sout(s1.toString()); // 直接打印包+类名+哈希值

// 重写 快捷键 alt + Ins
@override
public String toString()&#123;
  return &quot;Student [name = &quot; + name + &quot;, age = &quot; + age + &quot;]&quot;;
&#125;
</code></pre>
<h3 id="equals-类"><a href="#equals-类" class="headerlink" title="equals()类"></a>equals()类</h3><ol>
<li><code>public boolean equals(Object obj)&#123;&#125;</code></li>
<li>默认实现为(this == obj), 比较两个对象地址是否相同</li>
<li>可进行覆盖，比较两个对象的内容是否相同</li>
</ol>
<pre><code class="java">System.out.println(s1.equals(s2)); //false
Sstudent s3 = s1;
System.out.println(s1.equals(s3)); //true

Student eq1 = new Student(&quot;xm&quot;, 11);
Student eq2 = new Student(&quot;xm&quot;, 11);
System.out.println(eq1.equals(eq2)); //false,地址不同
</code></pre>
<p>​    重写equals()方法:</p>
<pre><code class="java">Entity中:
// 重写 改变其比较内容
/*
步骤  1. 比较两个应用是否指向同一个对象
     2. 判断obj是否为null
     3. 判断两个引用只想的实际对象类型是否一致
     4. 强制类型转换
     5. 依次比较各个属性值是否相同
*/
@override
public boolean equals(Object obj)&#123;
  // 1.
  if(this == obj)&#123;
    return true;
  &#125;
  // 2.
  if(obj == null)&#123;
    return false;
  &#125;
  // 3.
  // if(this.getClass() == obj.getClass())&#123;
  //
  // &#125;
  // instanceof 判断对象是否是某种类型
  if(obj instanceof Student)&#123;
    // 4.强制类型转换
    Student s = (Student)obj;
    // 5. 比较属性
    if(this.name.equals(s.getName()) &amp;&amp; this.age == s.getAge())&#123;
      return true;
    &#125;
  &#125;
  return false;
&#125;
</code></pre>
<h3 id="finalize-方法"><a href="#finalize-方法" class="headerlink" title="finalize()方法"></a>finalize()方法</h3><ol>
<li>当对象被判定为垃圾对象时，由JVM自动调用此方法，用以标记垃圾对象，进入回收队列</li>
<li>垃圾对象：没有有效引用指向此对象时，为垃圾对象</li>
<li>垃圾回收：由gc销毁垃圾对象，释放数据存储空间</li>
<li>自动回收机制：JVM的内存耗尽，一次性回收所有垃圾对象</li>
<li>手动回收机制：使用<code>System.gc();</code>通知JVM执行垃圾回收</li>
</ol>
<pre><code class="java">finalize默认为空，重写方法：
@Override
protected void finalize() throws Throwable&#123;
  sout(this.name + &quot;对象被回收了&quot;);
&#125;

Student s1 = new Student(&quot;aaa&quot;, 1);
new Student(&quot;aaa&quot;, 1);
//手动告诉JVM进行回收；
System.gc();
System.out.println(&quot;回收垃圾&quot;);
</code></pre>
<h2 id="包装类"><a href="#包装类" class="headerlink" title="包装类"></a>包装类</h2><ol>
<li><strong>基本数据类型</strong>所对应的<strong>引用数据类型</strong></li>
<li>Object 可统一所有数据，包装类的默认值是null</li>
</ol>
<table>
<thead>
<tr>
<th align="center">基本数据类型</th>
<th align="center">包装类型</th>
</tr>
</thead>
<tbody><tr>
<td align="center">byte</td>
<td align="center">Byte</td>
</tr>
<tr>
<td align="center">short</td>
<td align="center">Short</td>
</tr>
<tr>
<td align="center">int</td>
<td align="center">Integer</td>
</tr>
<tr>
<td align="center">long</td>
<td align="center">Long</td>
</tr>
<tr>
<td align="center">float</td>
<td align="center">Float</td>
</tr>
<tr>
<td align="center">double</td>
<td align="center">Double</td>
</tr>
<tr>
<td align="center">boolean</td>
<td align="center">Boolean</td>
</tr>
<tr>
<td align="center">char</td>
<td align="center">Character</td>
</tr>
</tbody></table>
<h3 id="类型转换与装箱、拆箱"><a href="#类型转换与装箱、拆箱" class="headerlink" title="类型转换与装箱、拆箱"></a><strong>类型转换与装箱、拆箱</strong></h3><ol>
<li>8种包装类提供不用类型间的转换方式<ol>
<li>Number父类中提供的6个共性方法</li>
<li><code>parseXXX( )</code>静态方法</li>
<li><code>valueOf( )</code>静态方法</li>
</ol>
</li>
<li>注意：需保证类型兼容，否则抛出<code>NumberFormatException</code>异常</li>
</ol>
<pre><code class="java">public static void main(String[] args) &#123;
        // 装箱， 基本类型 → 引用类型
        // 基本类型
        int num1 = 18;
        // 使用Integer类创建对象
        Integer integer1 = new Integer(num1);
        Integer integer2 = Integer.valueOf(num1);

        System.out.println(&quot;装箱&quot;);
        System.out.println(integer1);
        System.out.println(integer2);

        // 拆箱， 引用类型 → 基本类型
        Integer integer3 = new Integer(100);
        int num2 = integer3.intValue();

        System.out.println(&quot;拆箱&quot;);
        System.out.println(num2);

        //↑ JDK1.5 之前，JDK1.5之后自动装箱和拆箱
        int age = 30;
        //自动装箱
        Integer integer4 = age;
        System.out.println(&quot;自动装箱&quot;);
        System.out.println(integer4);
        //自动拆箱
        int age2 = integer4;

        System.out.println(&quot;自动拆箱&quot;);
        System.out.println(age2);
        System.out.println(&quot;---------------------------------------&quot;);
        //基本类型和字符串之间的转换
        //基本类型转换为字符串
        // 基本类型和字符串之间转换
        // 1. 基本类型转成字符串
        int n1 = 100;
        // 1.1 使用+号
        String s1 = n1 + &quot;&quot;;
        // 1.2 使用Integer中的toString()方法
        String s2 = Integer.toString(n1,2);
        System.out.println(s2);
       //String s2 = Integer.toString(n1, x); // x为进制要求

        // 2. 字符串转成基本类型
        String str = &quot;150&quot;;
        // 使用Integer.parseXXX();
        int n2 = Integer.parseInt(str);
        System.out.println(n2);

        // boolean 字符串形式转成基本类型，&quot;true&quot; ---&gt; true 非“true ———&gt; false
        String str2 = &quot;true&quot;;
        boolean b1 = Boolean.parseBoolean(str2);
        System.out.println(b1);
    &#125;
</code></pre>
<h2 id="整数缓冲区"><a href="#整数缓冲区" class="headerlink" title="整数缓冲区"></a>整数缓冲区</h2><ol>
<li>Java预先创建了256个常用的证书包装类型对象</li>
<li>在实际应用当中，对已创建的对象进行复用</li>
</ol>
<pre><code class="java">  public static void main(String[] args) &#123;
        // 面试题
        Integer integer1 = new Integer(100);
        Integer integer2 = new Integer(100);
        System.out.println(integer1 == integer2); // false

        Integer integer3 =  Integer.valueOf(100);// 自动装箱
        // 相当于调用 Integer.valueOf(100);
        Integer integer4 = Integer.valueOf(100);
        System.out.println(integer3 == integer4); // true

        Integer integer5 = Integer.valueOf(200);// 自动装箱
        Integer integer6 = Integer.valueOf(200);
        System.out.println(integer5 == integer6); // false

        // 因为缓存区数组 [-128, 127] 在这之内地址一样
    &#125;
</code></pre>
<h2 id="String类"><a href="#String类" class="headerlink" title="String类"></a>String类</h2><ol>
<li>字符串是final修饰的常量，创建之后不可改变</li>
<li>字符串字面值存储在字符串池中，可以共享</li>
<li><code>String s = &quot;Hello&quot;;</code>产生一个对象，字符串池中存储</li>
<li><code>String s = new String(&quot;Hello&quot;);</code> 产生两个对象，<strong>堆、池</strong>各一个</li>
</ol>
<pre><code class="java">public static void main(String[] args) &#123;

        // 1. length(); 返回字符串长度
        // 2. charAt(int index); 返回某个位置的字符
        // 3. contains(String str); 判断是否包含某个字符串

        String content = &quot;java是最好的语言, java no1&quot;;
        System.out.println(content.length()); // 10
        System.out.println(content.charAt(content.length() - 1)); // 言
        System.out.println(content.contains(&quot;java&quot;)); // true

        // 4. toCharArray(); 返回字符串对应数组
        // 5. indexOf(); 返回子字符串首次出现的位置
        // 6. lastIndexOf(); 返回字符串最后一次出现的位置

        System.out.println(content.toCharArray());
        System.out.println(content.indexOf(&quot;java&quot;)); // 0
        System.out.println(content.indexOf(&quot;java&quot;, 4)); // 从索引4开始找 返回12
        System.out.println(content.lastIndexOf(&quot;java&quot;)); // 12

        // 7. trim(); //去掉字符串前后空格
        // 8. toUpperCase(); toLowerCase(); 转换大小写
        // 9. endWith(str); startWith(str);  判断是否以str 结尾、开头

        String ct = &quot; hello world &quot;;
        System.out.println(ct.trim()); // &quot;hello world&quot;
        System.out.println(ct.toUpperCase()); // HELLO WORLD
        System.out.println(ct.toLowerCase()); // hello world
        System.out.println(ct.endsWith(&quot;world&quot;)); // true
        System.out.println(ct.startsWith(&quot;hello&quot;)); // true

        // 10. replace(char old, char new); 用心的字符或字符串替换旧的字符或字符串
        // 11. split(); 对字符串拆分

        System.out.println(content.replace(&quot;java&quot;, &quot;python&quot;)); // php是最好的语言, php no1

        String say = &quot;java is the best language&quot;;
        String[] arr = say.split(&quot; &quot;); // &quot;[ ,]+&quot; 表示空格 逗号切分 +号表示切分可以多个 比如多个空格
        System.out.println(arr.length); // 5
        for (String string : arr) &#123;
            System.out.println(string);
        &#125;
        // 打印出
        //java
        //is
        //the
        //best
        //language

        // 补充两个equals/compareTo();比较大小
        String s1 = &quot;hello&quot;;
        String s2 = &quot;HELLO&quot;;
        System.out.println(s1.equalsIgnoreCase(s2));// 忽略大小写比较true

        // compareTo(); 两字符不同时比较字符字典序的ascii码
        // 字符相同时比较长度 返回差值

    &#125;
</code></pre>
<h3 id="String-常用方法"><a href="#String-常用方法" class="headerlink" title="String 常用方法"></a>String 常用方法</h3><ol>
<li>length(); 返回字符串长度；</li>
<li>charAt(int index); 返回某个位置的字符；</li>
<li>contains(String str); 判断是否包含某个字符串；</li>
<li>toCharArray(); 返回字符串对应数组；</li>
<li>indexOf(); 返回子字符串首次出现的位置；</li>
<li>lastIndexOf(); 返回字符串最后一次出现的位置；</li>
<li>trim(); //去掉字符串前后空格；</li>
<li>toUpperCase(); toLowerCase(); 转换大小写；</li>
<li>endWith(str); startWith(str);  判断是否以str 结尾、开头；</li>
<li>replace(char old, char new); 用心的字符或字符串替换旧的字符或字符串；</li>
<li>split(); 对字符串拆分；</li>
</ol>
<h4 id="案例演示"><a href="#案例演示" class="headerlink" title="案例演示"></a>案例演示</h4><p>需求：</p>
<ol>
<li>已知String str = “this is a text”;</li>
<li>将str中的单词单独获取</li>
<li>将str中的text替换成practice</li>
<li>在text前面插入一个easy</li>
<li>将每个单词的首字母改为大写</li>
</ol>
<pre><code class="java">public static void main(String[] args) &#123;
//        已知String str = &quot;this is a text&quot;;
//        将str中的单词单独获取
//        将str中的text替换成practice
//        在text前面插入一个easy
//        将每个单词的首字母改为大写

        String str = &quot;this is a text&quot;;
        String[] arr = str.split(&quot; &quot;);
        for (String s : arr) &#123;
            System.out.println(s);
        &#125;


        str = str.replace(&quot;text&quot;, &quot;practice&quot;);
        System.out.println(str);

        str =  str.replace(&quot;practice&quot;, &quot;easy practice&quot;);
        System.out.println(str);

        for (int i = 0; i &lt; arr.length; i++) &#123;
            char first = arr[i].charAt(0);
            char upperfirst = Character.toUpperCase(first);
            String newstr = upperfirst + arr[i].substring(1);
            System.out.println(newstr);

        &#125;
    &#125;
</code></pre>
<h3 id="StringBuffer-和-StringBuilder"><a href="#StringBuffer-和-StringBuilder" class="headerlink" title="StringBuffer 和 StringBuilder"></a>StringBuffer 和 StringBuilder</h3><ol>
<li>StringBuffer : 可变长字符串，运行效率慢、线程安全</li>
<li>StringBuilder : 可边长字符串、运行快、线程不安全</li>
</ol>
<p>效率都比String高且节省内存</p>
<pre><code class="java">        StringBuffer sb = new StringBuffer();
        sb.append(&quot;java世界第一&quot;);
        System.out.println(sb.toString());
        sb.append(&quot;java真香&quot;);
        System.out.println(sb.toString());
        sb.append(&quot;java不错&quot;);
        System.out.println(sb.toString());
        sb.insert(0,&quot;我在最前面&quot;);
        System.out.println(sb.toString());
        sb.replace(0,5,&quot;hello&quot;);
        System.out.println(sb.toString());
        sb.delete(0,5);
        System.out.println(sb.toString());
        sb.delete(0,sb.length());
        System.out.println(&quot;delete&quot; + sb.toString());
</code></pre>
<p>测试效率：</p>
<pre><code class="java">    public static void main(String[] args) &#123;
        long start = System.currentTimeMillis();
        String str = &quot;&quot;;
        for (int i = 0; i &lt; 99999; i++) &#123;
            str+=i;
        &#125;

        long end = System.currentTimeMillis();

        System.out.println((float) (end-start)/1000 + &quot;s&quot;);


        long start2 = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer(&quot;&quot;);
        for (int i = 0; i &lt; 99999; i++) &#123;
            sb.append(i);
        &#125;

        long end2 = System.currentTimeMillis();

        System.out.println(end2-start2 + &quot;ms&quot;);

        long start3 = System.currentTimeMillis();
        StringBuilder sbu = new StringBuilder(&quot;&quot;);
        for (int i = 0; i &lt; 99999; i++) &#123;
            sbu.append(i);
        &#125;

        long end3 = System.currentTimeMillis();

        System.out.println(end3-start3 + &quot;ms&quot;);

    &#125;

输出结果：
18.49s
10ms
0ms
    
可见效率差距
</code></pre>
<h2 id="BigDecimal类"><a href="#BigDecimal类" class="headerlink" title="BigDecimal类"></a>BigDecimal类</h2><ol>
<li><p>位置 <code>java.math</code> 包中</p>
</li>
<li><p>作用 精确计算浮点数</p>
</li>
<li><p>创建方式 <code>BigDecimal bd = new BigDecimal(&quot;1.0&quot;);</code></p>
<pre><code class="java">public static void main(String[] args) &#123;
        double d1 = 1.0;
        double d2 = 0.9;
        System.out.println(&quot;d1-d2=&quot; + (d1-d2));

        double res = (1.4-0.5)/0.9;
        System.out.println(&quot;result=&quot; + res);


        BigDecimal bd1 = new BigDecimal(&quot;1.0&quot;);
        BigDecimal bd2 = new BigDecimal(&quot;0.9&quot;);

        BigDecimal bdres1 = bd1.add(bd2); //加
        BigDecimal bdres2 = bd1.subtract(bd2); //减
        BigDecimal bdres3 = bd1.multiply(bd2); //乘
        BigDecimal bdres4 = 
            bd1.divide(bd2,2,BigDecimal.ROUND_HALF_UP); //除
    // bd1.divide(除数,小数精确到几位,BigDecimal.ROUND_HALF_UP=四舍五入);
        System.out.println(&quot;加=&quot;+bdres1+&quot;\n减=&quot;+bdres2+&quot;\n乘=&quot;+bdres3+&quot;\n除=&quot;+bdres4);
    &#125;
</code></pre>
<pre><code class="java">d1-d2=0.09999999999999998
result=0.9999999999999999
加=1.9
减=0.1
乘=0.90
除=1.11
</code></pre>
</li>
</ol>
<h2 id="时间-Date类"><a href="#时间-Date类" class="headerlink" title="时间-Date类"></a>时间-Date类</h2><ol>
<li>Date表示特定的瞬间，精确到毫秒。Date类中的大部分方法都已经被Calendar类中的方法所取代; ( 时间单位：1s = 1,000ms = 1,000,000 μs = 1,000,000,000 = ns; ) </li>
</ol>
<pre><code class="java">public static void main(String[] args) &#123;
        Date date1 = new Date();
        System.out.println(date1.toString());
        System.out.println(date1.toLocaleString());

        //昨天
        Date date2 = new Date(date1.getTime() - (60*60*24*1000));
        System.out.println(date2.toLocaleString());


        //方法after before
        boolean b1 = date1.after(date2);
        System.out.println(b1);

        boolean b2 = date1.before(date2);
        System.out.println(b2);


        //比较compareTo(),比较毫秒值
        int d1 = date1.compareTo(date2);
        System.out.println(d1);

        int d2 = date1.compareTo(date1);
        System.out.println(d2);

        //比较是否相等
        boolean b3 = date1.equals(date2);
        System.out.println(b3);

    &#125;
</code></pre>
<h2 id="时间-Calendar类"><a href="#时间-Calendar类" class="headerlink" title="时间-Calendar类"></a>时间-Calendar类</h2><ol>
<li>Calendar提供了获取或设置各种日历字段的方法</li>
<li>构造方法 <code>protected Calendar();</code> 由于是protected 所以无法直接创建</li>
<li>其他方法</li>
</ol>
<table>
<thead>
<tr>
<th align="left">方法名</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="left">static Calendar getInstance()</td>
<td align="left">使用默认时区和区域获取日历</td>
</tr>
<tr>
<td align="left">void set(int year, int month, int date, int hourofday, int minute, int second)</td>
<td align="left">设置日历的年、月、日、时、分、秒</td>
</tr>
<tr>
<td align="left">int get(int field)</td>
<td align="left">返回给定日历字段的值。字段比如年、月、日</td>
</tr>
<tr>
<td align="left">void setTime(Date date)</td>
<td align="left">用给定的date设置此日历时间</td>
</tr>
<tr>
<td align="left">Date getTime()</td>
<td align="left">返回一个date表示此日历的时间</td>
</tr>
<tr>
<td align="left">void add(int field, int amount)</td>
<td align="left">按照日历的规则，给指定字段添加或减少时间量</td>
</tr>
<tr>
<td align="left">long getTimeInMilles()</td>
<td align="left">毫秒为单位返回该日历的时间值</td>
</tr>
</tbody></table>
<pre><code class="java">public static void main(String[] args) &#123;
        //创建Calendar对象
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.getTime().toString());
        System.out.println(calendar.getTimeInMillis());

        //获取时间信息
        //获取年
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int date = calendar.get(Calendar.DATE);
        int hour = calendar.get(Calendar.HOUR); //12时制
        int hour2 = calendar.get(Calendar.HOUR_OF_DAY);//24时制
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        String[] arr = &#123;&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;&#125;;
        String week2 = arr[week-1];
        System.out.println(year + &quot;/&quot; + (month+1) + &quot;/&quot; + date  + &quot;-&quot; + hour + &quot;(&quot;+ hour2 +&quot;)&quot;  + &quot;:&quot; + minute + &quot;:&quot; + second + &quot;-[ 星期&quot; + week2 + &quot;]&quot;);

        //修改时间
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(Calendar.DAY_OF_MONTH, 5);
        System.out.println(calendar1.getTime().toLocaleString());

        //add方法修改时间
        calendar1.add(Calendar.HOUR, 1);
        System.out.println(calendar1.getTime().toLocaleString());

        //补充方法
        int max = calendar1.getActualMaximum(Calendar.DAY_OF_MONTH); //本月最大多少天
        int min =  calendar1.getActualMinimum(Calendar.DAY_OF_MONTH);//本月最小多少天？
        System.out.println(max);
        System.out.println(min);

        calendar1.add(Calendar.MONTH, 1);
        System.out.println(calendar1.getTime().toLocaleString());
        
        int max2 = calendar1.getActualMaximum(Calendar.DAY_OF_MONTH); //本月最大多少天
        int min2 =  calendar1.getActualMinimum(Calendar.DAY_OF_MONTH);//本月最小多少天？
        System.out.println(max2);
        System.out.println(min2);

    &#125;
</code></pre>
<pre><code class="powershell">Tue Apr 06 21:25:51 CST 2021
1617715551128
2021/4/6-9(21):25:51-[星期二]
2021-4-5 21:25:51
2021-4-5 22:25:51
30
1
2021-5-5 22:25:51
31
1
</code></pre>
<h2 id="SimpleDateFormat类"><a href="#SimpleDateFormat类" class="headerlink" title="SimpleDateFormat类"></a>SimpleDateFormat类</h2><ol>
<li>SimpleDateFormat是一个以与语言环境有关的方式来格式化和解析日期的具体类</li>
<li>进行格式化（日期→文本）、解析（文本→日期）</li>
<li>常用的时间模式字母</li>
</ol>
<table>
<thead>
<tr>
<th align="left">字母</th>
<th align="left">日期或时间</th>
<th align="left">示例</th>
</tr>
</thead>
<tbody><tr>
<td align="left">y</td>
<td align="left">年</td>
<td align="left">2019</td>
</tr>
<tr>
<td align="left">08</td>
<td align="left">年中月份</td>
<td align="left">08</td>
</tr>
<tr>
<td align="left">d</td>
<td align="left">月中天数</td>
<td align="left">10</td>
</tr>
<tr>
<td align="left">H</td>
<td align="left">一天中小时（0-23）</td>
<td align="left">22</td>
</tr>
<tr>
<td align="left">m</td>
<td align="left">分钟</td>
<td align="left">16</td>
</tr>
<tr>
<td align="left">s</td>
<td align="left">秒</td>
<td align="left">59</td>
</tr>
<tr>
<td align="left">S</td>
<td align="left">毫秒</td>
<td align="left">356</td>
</tr>
</tbody></table>
<pre><code class="java"> public static void main(String[] args) throws Exception&#123;
        SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy年MM月dd日 HH:mm:ss&quot;);

        Date date = new Date();
        String str = sdf.format(date);
        System.out.println(str);

        Date date2 = sdf.parse(&quot;1990/05/01&quot;);
        System.out.println(date2);
    &#125;
</code></pre>
<h2 id="System类"><a href="#System类" class="headerlink" title="System类"></a>System类</h2><p>主要用于获取系统的属性数据和其他操作，构造方法私有的</p>
<table>
<thead>
<tr>
<th align="left">方法名</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="left">static void arraycopy(…)</td>
<td align="left">复制数组</td>
</tr>
<tr>
<td align="left">static long currentTimeMillis();</td>
<td align="left">获取当前系统时间，返回毫秒值</td>
</tr>
<tr>
<td align="left">static void gc();</td>
<td align="left">建议jvm赶快启动垃圾回收期器回收垃圾</td>
</tr>
<tr>
<td align="left">static void exit(int status);</td>
<td align="left">退出jvm 如果参数是0表示正常退出jvm 非0表示异常退出</td>
</tr>
</tbody></table>
<pre><code class="java">public static void main(String[] args) &#123;
        // arrcopy 数组的复制
        // src: 源数组
        // srcPos: 从哪个位置开始复制 0
        // dest: 目标数组
        // destPos: 目标数组的位置
        // length: 复制的长度
        int[] arr = &#123;20, 10, 15, 8, 35, 26, 45, 90&#125;;
        int[] targetarr = new int[8];

        System.arraycopy(arr, 4, targetarr, 6,2);
        System.out.println(Arrays.toString(targetarr));

        //Arrays.copyOf()底层源码实现方式依旧为arraycopy
        int[] targetarr2 = Arrays.copyOf(arr,6);
        System.out.println(Arrays.toString(targetarr2));

        //退出JVM,下面的代码不再执行
        System.exit(0);
        System.out.println(&quot;程序结束了···········&quot;);
    &#125;
</code></pre>

  </article>

  
    
  <div class="nexmoe-post-copyright">
    <strong>本文作者：</strong>shanX<br>
    <strong>本文链接：</strong><a href="https://rhymexmove.github.io/2021/04/06/e3cec34b39ef/" title="https:&#x2F;&#x2F;rhymexmove.github.io&#x2F;2021&#x2F;04&#x2F;06&#x2F;e3cec34b39ef&#x2F;" target="_blank" rel="noopener">https:&#x2F;&#x2F;rhymexmove.github.io&#x2F;2021&#x2F;04&#x2F;06&#x2F;e3cec34b39ef&#x2F;</a><br>
    
      <strong>版权声明：</strong>本文采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/deed.zh" target="_blank">CC BY-NC-SA 3.0 CN</a> 协议进行许可
    
  </div>


  
  
  <div class="nexmoe-post-meta nexmoe-rainbow">
    
        <a class="nexmoefont icon-appstore-fill -link" href="/categories/java/">java</a>
    
    
        <a class="nexmoefont icon-tag-fill -none-link" href="/tags/java%E5%9F%BA%E7%A1%80/" rel="tag">java基础</a>
    
</div>

  <div class="nexmoe-post-footer">
    <section class="nexmoe-comment">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.min.css">
<div id="gitalk"></div>
<script src="https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.min.js"></script>
<script type="text/javascript">
    var gitalk = new Gitalk({
        clientID: 'a2d666d91d6af126f538',
        clientSecret: '9c79e44494cd9fae312629457ae9b534e01a963e',
        id: decodeURI(window.location.pathname),
        repo: 'RhymeXmove.github.io',
        owner: 'RhymeXmove',
        admin: 'RhymeXmove'
    })
    gitalk.render('gitalk')
</script>
</section>
  </div>
</div>
                            <div class="nexmoe-post-right">
                                <div class="nexmoe-fixed">
                                    <div class="nexmoe-tool">
                                        <a href="#nexmoe-content" class="toc-link" aria-label="回到顶部" title="top"><button class="mdui-fab mdui-ripple"><i class="nexmoefont icon-caret-top"></i></button></a>
                                    </div>
                                </div>
                            </div>
                    </div>
                </div>
                <script src="https://cdn.jsdelivr.net/combine/npm/lazysizes@5.1.0/lazysizes.min.js,gh/highlightjs/cdn-release@9.15.8/build/highlight.min.js,npm/mdui@0.4.3/dist/js/mdui.min.js?v=1"></script>
<script>
	hljs.initHighlightingOnLoad();
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>


<script src="https://cdn.jsdelivr.net/gh/xtaodada/xtaodada.github.io@0.0.2/copy.js"></script>
 

<script src="/js/app.js?v=1649858550961"></script>

<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.8.1/dist/js/jquery.justifiedGallery.min.js"></script>
<script>
	$(".justified-gallery").justifiedGallery({
		rowHeight: 160,
		margins: 10,
	});
</script>

                    





        </body>

</html>